﻿using System;
using System.Windows.Data;
using NetBay.Core.BusinessEntities;
using NetBay.Core.BusinessEntities.Versioning;
using Rio.Framework.Pages.Extensions;

namespace Rio.Framework.Pages.AppCode.Helpers.Converter
{
    public class MajorMinorToBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object returnValue = value;

            Document currentDocument = (Document)value;

            switch (currentDocument.CurrentModelVersion.ModelType)
            {
                case VersionType.None:
                    throw new Exception("No version type has been defined for this folder type.");
                    //break;
                case VersionType.NoControl:
                    returnValue = false;
                    break;
                case VersionType.Major:
                    returnValue = ((string)parameter).ToLowerInvariant() == "major" ? !currentDocument.MaxMajorReached() : false;
                    break;
                case VersionType.MajorMinor:
                    if (((string)parameter).ToLowerInvariant() == "major")
                        returnValue = !currentDocument.MaxMajorReached() ;
                    else
                        returnValue = !currentDocument.MaxMinorReached() ;
                    break;
                default:
                    break;
            }

            return returnValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
